﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeFirst.Models.Mapping
{
    class StudentMap : EntityTypeConfiguration<Student>
    {
        public StudentMap()
        {
            // Primary Key
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(12);

            // Table & Column Mappings
            ToTable("Students");
            Property(t => t.Id).HasColumnName("Id");
            Property(t => t.Name).HasColumnName("Name");

            // Relationships
            HasRequired(t => t.Grade)
                .WithMany(t => t.Students)
                .HasForeignKey(t => t.GradeId);

        }
    }
}
